hwmon: (max6650.c) Add devicetree support
PATCH v4 1/1 hwmon: (max6650.c) Add devicetree support
Parse devicetree parameters for voltage and prescaler setting. This allows using multiple max6550 devices with varying settings, and also makes it possible to instantiate and configure the device using devicetree.
---
v4: Vendor prefix "maxim," for devicetree properties and compatible string
Split documentation into separate patch
v3: Resubmit because wrong mailing lists used
Fix style errors as reported by checkpatch.pl
Fix bug in DT parsing of fan-prescale
v2: Add devicetree binding documentation
Code changes as suggested by Guenter
Reduce log info, output only a single line
drivers/hwmon/max6650.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-)
drivers/hwmon/max6650.c +36 -11
@@ -39,6 +39,7 @@#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> +#include <linux/of_device.h> /* * Insmod parameters
@@ -48,7 +49,7 @@static int fan_voltage;/* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */ static int prescaler; -/* clock: The clock frequency of the chip the driver should assume */ +/* clock: The clock frequency of the chip (max6651 can be clocked externally) */ static int clock =254000 ;module_param (fan_voltage, int,S_IRUGO );
@@ -133,6 +134,19 @@ static const u8 tach_reg[] = { MAX6650_REG_TACH3, }; +static const struct of_device_id max6650_dt_match[] = { + { + .compatible ="maxim,max6650" , + .data = (void *)1 + }, + { + .compatible ="maxim,max6651" , + .data = (void *)4 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, max6650_dt_match); +static struct max6650_data *max6650_update_device (struct device *dev) {struct max6650_data *data =dev_get_drvdata (dev);
@@ -566,6 +580,17 @@ static int max6650_init_client(struct max6650_data *data,struct device *dev = &client->dev;int config;int err = -EIO ; +u32 voltage; +u32 prescale; + +if (of_property_read_u32 (dev->of_node,"maxim,fan-microvolt" , + &voltage)) + voltage = fan_voltage; +else + voltage = voltage >5500000 ?12 :5 ; +if (of_property_read_u32 (dev->of_node,"maxim,fan-prescale" , + &prescale)) + prescale = prescaler; config =i2c_smbus_read_byte_data (client,MAX6650_REG_CONFIG );
@@ -574,7 +599,7 @@ static int max6650_init_client(struct max6650_data *data,return err; } -switch (fan_voltage) { +switch (voltage) {case 0 :break ;case 5 :
@@ -584,14 +609,10 @@ static int max6650_init_client(struct max6650_data *data, config |=MAX6650_CFG_V12 ;break ;default : -dev_err (dev,"illegal value for fan_voltage (%d)\n" , - fan_voltage); +dev_err (dev,"illegal value for fan_voltage (%d)\n" , voltage); } -dev_info (dev,"Fan voltage is set to %dV.\n" , - (config &MAX6650_CFG_V12 ) ?12 :5 ); - -switch (prescaler) { +switch (prescale) {case 0 :break ;case 1 :
@@ -614,10 +635,11 @@ static int max6650_init_client(struct max6650_data *data, | MAX6650_CFG_PRESCALER_16;break ;default : -dev_err (dev,"illegal value for prescaler (%d)\n" , prescaler); +dev_err (dev,"illegal value for prescaler (%d)\n" , prescale); } -dev_info (dev,"Prescaler is set to %d.\n" , +dev_info (dev,"Fan voltage: %dV, prescaler: %d.\n" , + (config &MAX6650_CFG_V12 ) ?12 :5 ,1 << (config &MAX6650_CFG_PRESCALER_MASK ));/*
@@ -651,6 +673,8 @@ static int max6650_probe(struct i2c_client *client, const struct i2c_device_id *id) {struct device *dev = &client->dev; +const struct of_device_id *of_id = +of_match_device (of_match_ptr (max6650_dt_match), dev);struct max6650_data *data;struct device *hwmon_dev;int err;
@@ -661,7 +685,7 @@ static int max6650_probe(struct i2c_client *client, data->client = client;mutex_init (&data->update_lock); - data->nr_fans = id->driver_data; + data->nr_fans = of_id ? (int )(uintptr_t )of_id->data : id->driver_data;/* * Initialize the max6650 chip
@@ -691,6 +715,7 @@ MODULE_DEVICE_TABLE(i2c, max6650_id);static struct i2c_driver max6650_driver = { .driver = { .name ="max6650" , + .of_match_table =of_match_ptr (max6650_dt_match), }, .probe = max6650_probe, .id_table = max6650_id,
Signature · 1 line
1.9.1
Guenter Roeck
maintainerQuoted 60 lines · Mike Looijmans
Parse devicetree parameters for voltage and prescaler setting. This allows using multiple max6550 devices with varying settings, and also makes it possible to instantiate and configure the device using devicetree.
Signed-off-by Mike Looijmans <[email protected]>---
v4: Vendor prefix "maxim," for devicetree properties and compatible string
Split documentation into separate patch
v3: Resubmit because wrong mailing lists used
Fix style errors as reported by checkpatch.pl
Fix bug in DT parsing of fan-prescale
v2: Add devicetree binding documentation
Code changes as suggested by Guenter
Reduce log info, output only a single linedrivers/hwmon/max6650.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-)drivers/hwmon/max6650.c +15
-1@@ -39,6 +39,7 @@#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> +#include <linux/of_device.h> /* * Insmod parameters @@ -48,7 +49,7 @@static int fan_voltage;/* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */ static int prescaler; -/* clock: The clock frequency of the chip the driver should assume */ +/* clock: The clock frequency of the chip (max6651 can be clocked externally) */ static int clock =254000 ;module_param (fan_voltage, int,S_IRUGO );@@ -133,6 +134,19 @@ static const u8 tach_reg[] = { MAX6650_REG_TACH3, }; +static const struct of_device_id max6650_dt_match[] = { + { + .compatible ="maxim,max6650" , + .data = (void *)1 + }, + { + .compatible ="maxim,max6651" , + .data = (void *)4 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, max6650_dt_match); +static struct max6650_data *max6650_update_device (struct device *dev) {struct max6650_data *data =dev_get_drvdata (dev);@@ -566,6 +580,17 @@ static int max6650_init_client(struct max6650_data *data,struct device *dev = &client->dev;
drivers/hwmon/max6650.c static int max6650_init_client(struct max6650_data *data, · line 590
Quoted 10 lines
drivers/hwmon/max6650.c +8
-0int config;int err = -EIO ; +u32 voltage; +u32 prescale; + +if (of_property_read_u32 (dev->of_node,"maxim,fan-microvolt" , + &voltage)) + voltage = fan_voltage; +else + voltage = voltage >5500000 ?12 :5 ;
I think this should only accept 5V or 12V.
Guenter
Quoted 73 lines
drivers/hwmon/max6650.c +13
-10+if (of_property_read_u32 (dev->of_node,"maxim,fan-prescale" , + &prescale)) + prescale = prescaler; config =i2c_smbus_read_byte_data (client,MAX6650_REG_CONFIG );@@ -574,7 +599,7 @@ static int max6650_init_client(struct max6650_data *data,return err; } -switch (fan_voltage) { +switch (voltage) {case 0 :break ;case 5 :@@ -584,14 +609,10 @@ static int max6650_init_client(struct max6650_data *data, config |=MAX6650_CFG_V12 ;break ;default : -dev_err (dev,"illegal value for fan_voltage (%d)\n" , - fan_voltage); +dev_err (dev,"illegal value for fan_voltage (%d)\n" , voltage); } -dev_info (dev,"Fan voltage is set to %dV.\n" , - (config &MAX6650_CFG_V12 ) ?12 :5 ); - -switch (prescaler) { +switch (prescale) {case 0 :break ;case 1 :@@ -614,10 +635,11 @@ static int max6650_init_client(struct max6650_data *data, | MAX6650_CFG_PRESCALER_16;break ;default : -dev_err (dev,"illegal value for prescaler (%d)\n" , prescaler); +dev_err (dev,"illegal value for prescaler (%d)\n" , prescale); } -dev_info (dev,"Prescaler is set to %d.\n" , +dev_info (dev,"Fan voltage: %dV, prescaler: %d.\n" , + (config &MAX6650_CFG_V12 ) ?12 :5 ,1 << (config &MAX6650_CFG_PRESCALER_MASK ));/* @@ -651,6 +673,8 @@ static int max6650_probe(struct i2c_client *client, const struct i2c_device_id *id) {struct device *dev = &client->dev; +const struct of_device_id *of_id = +of_match_device (of_match_ptr (max6650_dt_match), dev);struct max6650_data *data;struct device *hwmon_dev;int err;@@ -661,7 +685,7 @@ static int max6650_probe(struct i2c_client *client, data->client = client;mutex_init (&data->update_lock); - data->nr_fans = id->driver_data; + data->nr_fans = of_id ? (int )(uintptr_t )of_id->data : id->driver_data;/* * Initialize the max6650 chip @@ -691,6 +715,7 @@ MODULE_DEVICE_TABLE(i2c, max6650_id);static struct i2c_driver max6650_driver = { .driver = { .name ="max6650" , + .of_match_table =of_match_ptr (max6650_dt_match), }, .probe = max6650_probe, .id_table = max6650_id,
Quoted 75 lines · Guenter Roeck
Quoted 61 lines · Mike Looijmans
Parse devicetree parameters for voltage and prescaler setting. This allows using multiple max6550 devices with varying settings, and also makes it possible to instantiate and configure the device using devicetree.
Signed-off-by Mike Looijmans <[email protected]>---
v4: Vendor prefix "maxim," for devicetree properties and compatible string Split documentation into separate patch
v3: Resubmit because wrong mailing lists used
Fix style errors as reported by checkpatch.pl
Fix bug in DT parsing of fan-prescale
v2: Add devicetree binding documentation
Code changes as suggested by Guenter
Reduce log info, output only a single linedrivers/hwmon/max6650.c| 47 ++++++++++++++++++++++++++++++++++++-----------1 file changed, 36 insertions(+), 11 deletions(-)drivers/hwmon/max6650.c +2
-1@@ -39,6 +39,7 @@ #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> +#include <linux/of_device.h> /** Insmod parameters @@ -48,7 +49,7 @@ static int fan_voltage; /* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */ static int prescaler; -/* clock: The clock frequency of the chip the driver should assume */ +/* clock: The clock frequency of the chip (max6651 can be clocked externally) */
static int clock = 254000;module_param(fan_voltage, int,
S_IRUGO);drivers/hwmon/max6650.c +13
-0@@ -133,6 +134,19 @@ static const u8 tach_reg[] = { MAX6650_REG_TACH3, }; +static const struct of_device_id max6650_dt_match[] = { + { + .compatible = "maxim,max6650", + .data = (void *)1 + }, + { + .compatible = "maxim,max6651", + .data = (void *)4 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, max6650_dt_match); + static struct max6650_data *max6650_update_device(struct device *dev) { struct max6650_data *data = dev_get_drvdata(dev);@@ -566,6 +580,17 @@ static int max6650_init_client(struct max6650_data *data, struct device *dev = &client->dev;drivers/hwmon/max6650.c static int max6650_init_client(struct max6650_data *data, · line 590
Quoted 10 lines
drivers/hwmon/max6650.c +8
-0int config; int err = -EIO; + u32 voltage; + u32 prescale; + + if (of_property_read_u32(dev->of_node, "maxim,fan-microvolt", + &voltage)) + voltage = fan_voltage; + else + voltage = voltage > 5500000 ? 12 : 5;I think this should only accept 5V or 12V.
Quoted 1 line
Guenter
A 4V, 10V or 13V fan will also work just fine, the voltage register just sets the range of the feedback tachometer.
I don't have strong feelings either way, so if you feel the drive should bail out on anything but 5 or 12, that's fine with me too.
Should I change this and send a v5 patch?
Quoted 62 lines
Quoted 62 lines
drivers/hwmon/max6650.c +4
-1+ if (of_property_read_u32(dev->of_node, "maxim,fan-prescale", + &prescale)) + prescale = prescaler; config = i2c_smbus_read_byte_data(client, MAX6650_REG_CONFIG);@@ -574,7 +599,7 @@ static int max6650_init_client(struct max6650_data *data, return err; } - switch (fan_voltage) { + switch (voltage) {case 0:
break;
case 5:drivers/hwmon/max6650.c +0
-0@@ -584,14 +609,10 @@ static int max6650_init_client(struct max6650_data *data, config |= MAX6650_CFG_V12; break;default:
- dev_err(dev, "illegal value forfan_voltage(%d)\n",
- fan_voltage);
+ dev_err(dev, "illegal value forfan_voltage(%d)\n", voltage); }- dev_info(dev, "Fan voltage is set to %dV.\n",
- (config &MAX6650_CFG_V12) ? 12 : 5); -
- switch (prescaler) {
+ switch (prescale) {
case 0:
break;
case 1:drivers/hwmon/max6650.c +0
-0@@ -614,10 +635,11 @@ static int max6650_init_client(struct max6650_data *data, | MAX6650_CFG_PRESCALER_16; break;default:
- dev_err(dev, "illegal value for prescaler (%d)\n", prescaler);
+ dev_err(dev, "illegal value for prescaler (%d)\n", prescale); }- dev_info(dev, "Prescaler is set to %d.\n",
+ dev_info(dev, "Fan voltage: %dV, prescaler: %d.\n",
+ (config &MAX6650_CFG_V12) ? 12 : 5, 1 << (config &MAX6650_CFG_PRESCALER_MASK));/*
drivers/hwmon/max6650.c +3
-1@@ -651,6 +673,8 @@ static int max6650_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; + const struct of_device_id *of_id = + of_match_device(of_match_ptr(max6650_dt_match), dev); struct max6650_data *data; struct device *hwmon_dev; int err;@@ -661,7 +685,7 @@ static int max6650_probe(struct i2c_client *client, data->client = client; mutex_init(&data->update_lock); - data->nr_fans = id->driver_data; + data->nr_fans = of_id ? (int)(uintptr_t)of_id->data : id->driver_data;
Quoted 12 lines
drivers/hwmon/max6650.c MODULE_DEVICE_TABLE(i2c, max6650_id); · line 721
Quoted 11 lines
drivers/hwmon/max6650.c +1
-0/** Initialize the max6650 chip @@ -691,6 +715,7 @@ MODULE_DEVICE_TABLE(i2c, max6650_id); static struct i2c_driver max6650_driver = { .driver = { .name = "max6650", + .of_match_table = of_match_ptr(max6650_dt_match), }, .probe = max6650_probe, .id_table = max6650_id,
Kind regards,
Mike Looijmans
System Expert
TOPIC Products
Materiaalweg 4
5681 RJ Best
T:
+31 (0) 499 33 69 69
Postbus 440
E:
[email protected]
5680 AK Best
W:
www.topicproducts.com
The Netherlands
Please consider the environment before printing this e-mail
Topic zoekt gedreven (embedded) software specialisten!
(resent through different SMTP server, bounced as spam because of company server's unwanted modifications, sorry if you received this twice now)
Quoted 75 lines · Guenter Roeck
Quoted 61 lines · Mike Looijmans
Parse devicetree parameters for voltage and prescaler setting. This allows using multiple max6550 devices with varying settings, and also makes it possible to instantiate and configure the device using devicetree.
Signed-off-by Mike Looijmans <[email protected]>---
v4: Vendor prefix "maxim," for devicetree properties and compatible string
Split documentation into separate patch
v3: Resubmit because wrong mailing lists used
Fix style errors as reported by checkpatch.pl
Fix bug in DT parsing of fan-prescale
v2: Add devicetree binding documentation
Code changes as suggested by Guenter
Reduce log info, output only a single linedrivers/hwmon/max6650.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-)drivers/hwmon/max6650.c +2
-1@@ -39,6 +39,7 @@#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> +#include <linux/of_device.h> /* * Insmod parameters @@ -48,7 +49,7 @@static int fan_voltage;/* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */ static int prescaler; -/* clock: The clock frequency of the chip the driver should assume */ +/* clock: The clock frequency of the chip (max6651 can be clocked externally) */
static int clock = 254000;
module_param(fan_voltage, int, S_IRUGO);drivers/hwmon/max6650.c +13
-0@@ -133,6 +134,19 @@ static const u8 tach_reg[] = { MAX6650_REG_TACH3, }; +static const struct of_device_id max6650_dt_match[] = { + { + .compatible ="maxim,max6650" , + .data = (void *)1 + }, + { + .compatible ="maxim,max6651" , + .data = (void *)4 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, max6650_dt_match); +static struct max6650_data *max6650_update_device (struct device *dev) {struct max6650_data *data =dev_get_drvdata (dev);@@ -566,6 +580,17 @@ static int max6650_init_client(struct max6650_data *data,struct device *dev = &client->dev;drivers/hwmon/max6650.c static int max6650_init_client(struct max6650_data *data, · line 590
Quoted 10 lines
drivers/hwmon/max6650.c +8
-0int config;int err = -EIO ; +u32 voltage; +u32 prescale; + +if (of_property_read_u32 (dev->of_node,"maxim,fan-microvolt" , + &voltage)) + voltage = fan_voltage; +else + voltage = voltage >5500000 ?12 :5 ;I think this should only accept 5V or 12V.
Quoted 1 line
Guenter
A 4V, 10V or 13V fan will also work just fine, the voltage register just sets the range of the feedback tachometer.
I don't have strong feelings either way, so if you feel the drive should bail out on anything but 5 or 12, that's fine with me too.
Should I change this and send a v5 patch?
Quoted 74 lines
Quoted 73 lines
drivers/hwmon/max6650.c +13
-10+if (of_property_read_u32 (dev->of_node,"maxim,fan-prescale" , + &prescale)) + prescale = prescaler; config =i2c_smbus_read_byte_data (client,MAX6650_REG_CONFIG );@@ -574,7 +599,7 @@ static int max6650_init_client(struct max6650_data *data,return err; } -switch (fan_voltage) { +switch (voltage) {case 0 :break ;case 5 :@@ -584,14 +609,10 @@ static int max6650_init_client(struct max6650_data *data, config |=MAX6650_CFG_V12 ;break ;default : -dev_err (dev,"illegal value for fan_voltage (%d)\n" , - fan_voltage); +dev_err (dev,"illegal value for fan_voltage (%d)\n" , voltage); } -dev_info (dev,"Fan voltage is set to %dV.\n" , - (config &MAX6650_CFG_V12 ) ?12 :5 ); - -switch (prescaler) { +switch (prescale) {case 0 :break ;case 1 :@@ -614,10 +635,11 @@ static int max6650_init_client(struct max6650_data *data, | MAX6650_CFG_PRESCALER_16;break ;default : -dev_err (dev,"illegal value for prescaler (%d)\n" , prescaler); +dev_err (dev,"illegal value for prescaler (%d)\n" , prescale); } -dev_info (dev,"Prescaler is set to %d.\n" , +dev_info (dev,"Fan voltage: %dV, prescaler: %d.\n" , + (config &MAX6650_CFG_V12 ) ?12 :5 ,1 << (config &MAX6650_CFG_PRESCALER_MASK ));/* @@ -651,6 +673,8 @@ static int max6650_probe(struct i2c_client *client, const struct i2c_device_id *id) {struct device *dev = &client->dev; +const struct of_device_id *of_id = +of_match_device (of_match_ptr (max6650_dt_match), dev);struct max6650_data *data;struct device *hwmon_dev;int err;@@ -661,7 +685,7 @@ static int max6650_probe(struct i2c_client *client, data->client = client;mutex_init (&data->update_lock); - data->nr_fans = id->driver_data; + data->nr_fans = of_id ? (int )(uintptr_t )of_id->data : id->driver_data;/* * Initialize the max6650 chip @@ -691,6 +715,7 @@ MODULE_DEVICE_TABLE(i2c, max6650_id);static struct i2c_driver max6650_driver = { .driver = { .name ="max6650" , + .of_match_table =of_match_ptr (max6650_dt_match), }, .probe = max6650_probe, .id_table = max6650_id,
Guenter Roeck
maintainerQuoted 78 lines · Mike Looijmans
(resent through different SMTP server, bounced as spam because of company server's unwanted modifications, sorry if you received this twice now)
Quoted 75 lines · Guenter Roeck
Quoted 61 lines · Mike Looijmans
Parse devicetree parameters for voltage and prescaler setting. This allows using multiple max6550 devices with varying settings, and also makes it possible to instantiate and configure the device using devicetree.
Signed-off-by Mike Looijmans <[email protected]>---
v4: Vendor prefix "maxim," for devicetree properties and compatible string
Split documentation into separate patch
v3: Resubmit because wrong mailing lists used
Fix style errors as reported by checkpatch.pl
Fix bug in DT parsing of fan-prescale
v2: Add devicetree binding documentation
Code changes as suggested by Guenter
Reduce log info, output only a single linedrivers/hwmon/max6650.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-)drivers/hwmon/max6650.c +2
-1@@ -39,6 +39,7 @@#include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> #include <linux/err.h> +#include <linux/of_device.h> /* * Insmod parameters @@ -48,7 +49,7 @@static int fan_voltage;/* prescaler: Possible values are 1, 2, 4, 8, 16 or 0 for don't change */ static int prescaler; -/* clock: The clock frequency of the chip the driver should assume */ +/* clock: The clock frequency of the chip (max6651 can be clocked externally) */
static int clock = 254000;
module_param(fan_voltage, int, S_IRUGO);drivers/hwmon/max6650.c +13
-0@@ -133,6 +134,19 @@ static const u8 tach_reg[] = { MAX6650_REG_TACH3, }; +static const struct of_device_id max6650_dt_match[] = { + { + .compatible ="maxim,max6650" , + .data = (void *)1 + }, + { + .compatible ="maxim,max6651" , + .data = (void *)4 + }, + { }, +}; +MODULE_DEVICE_TABLE (of, max6650_dt_match); +static struct max6650_data *max6650_update_device (struct device *dev) {struct max6650_data *data =dev_get_drvdata (dev);@@ -566,6 +580,17 @@ static int max6650_init_client(struct max6650_data *data,struct device *dev = &client->dev;drivers/hwmon/max6650.c static int max6650_init_client(struct max6650_data *data, · line 590
Quoted 10 lines
drivers/hwmon/max6650.c +8
-0int config;int err = -EIO ; +u32 voltage; +u32 prescale; + +if (of_property_read_u32 (dev->of_node,"maxim,fan-microvolt" , + &voltage)) + voltage = fan_voltage; +else + voltage = voltage >5500000 ?12 :5 ;I think this should only accept 5V or 12V.
Quoted 6 lines
Quoted 1 line
Guenter
A 4V, 10V or 13V fan will also work just fine, the voltage register just sets the range of the feedback tachometer.
I don't have strong feelings either way, so if you feel the drive should bail out on anything but 5 or 12, that's fine with me too.
Problem with above code is that it isn't clear when the 5V vs. the 12V limit is set. 0V results in 5V, 5.5V results in 5V, 5.500001V results in 12V. That looks pretty arbitrary. On top of that, the datasheet only mentions 5V and 12V fans, and I am not aware of the others you are talking about. Per datasheet, the bit selects either 5V or 12V as fan voltage. So we should stick with that.
Quoted 2 lines
Should I change this and send a v5 patch?
Yes, please.
Guenter